<?php
/**
 * NAME: sjp
 * WHEN: OnMsg
 * PROVIDES: !sjp
 * AUTOLOAD: false
 * DESCRIPTION: Sprawdzanie slowa w slowniku jezyka polskiego
 * VERSION: 0.1
 * UPDATE: http://update.tempaq2.blacksoft.eu/check.php
 * AUTHOR: blacksoft.eu
 */
  
 exit();
 
//*function_start
	if ($d[0] == '!sjp' && isset($d[1])) {
		$adres = 'http://sjp.pwn.pl/lista.php?co=';
		$lista = '<!-- listahasel -->';
		$lista_end = '<!-- /listahasel -->';
		$msg = urlencode($bot->my_iconv('iso-8859-2', substr($message, strpos($message, $d[1]))));
		$msg = str_replace(' ', '+', $msg);
		
		$table = new table('sjp_cache');
		if (count($a = $table->select('haslo', $msg))) {
			debug('Wyciągam z cache\'u haslo: '.$msg, DBG_INFO, 2);
			$bot->send($a[0]['tresc']);
		} else {
			//	debug($adres.$msg);
			if ($stream = @fopen($adres.$msg, 'r')) {
				$tresc = stream_get_contents($stream, -1, 1185);
				//debug(substr($tresc, 0, 50));
				if (strstr($tresc, $lista)!==false) {
					$tresc = substr($tresc, strpos($tresc, $lista));
					$tresc = substr($tresc, 0, strpos($tresc, $lista_end));
					$tresc = str_replace(array("\n","\r"), ' ', html_entity_decode(trim($bot->my_iconv('bez-ogonkow', strip_tags($tresc)))));
					$a = strpos($tresc, '&#8226;');
					$tresc = substr($tresc, 0, (($a==0)?400:$a));
					$table->insert(array('haslo'=>$msg, 'tresc'=>$tresc));
					$bot->send($tresc);
				} else {
					$bot->send('Nie znaleziono hasła');
				}
			} else {
				$bot->send('Błąd łączenia');
			}
			fclose($stream);
		}
		unset($table);
	}
//*function_end
?>